package com.yunfeisoft.business.service.impl;

import com.yunfeisoft.base.model.WorkflowInstance;
import com.yunfeisoft.business.dao.inter.PrincipleApprovalDao;
import com.yunfeisoft.business.model.PrincipleApproval;
import com.yunfeisoft.business.service.inter.PrincipleApprovalService;
import com.yunfeisoft.common.base.BaseServiceImpl;
import com.yunfeisoft.common.sql.separation.DataSourceChange;
import com.yunfeisoft.common.utils.DateUtils;
import com.yunfeisoft.common.utils.Page;
import com.yunfeisoft.utils.WorkflowHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * ClassName: PrincipleApprovalServiceImpl
 * Description: 员工违纪审批表service实现
 * Author: Jackie liu
 * Date: 2020-05-14
 */
@Service("principleApprovalService")
public class PrincipleApprovalServiceImpl extends BaseServiceImpl<PrincipleApproval, String, PrincipleApprovalDao> implements PrincipleApprovalService {

    @Autowired
    private WorkflowHelper workflowHelper;

    @Override
    @DataSourceChange(slave = true)
    public Page<PrincipleApproval> queryPage(Map<String, Object> params) {
        return getDao().queryPage(params);
    }

    @Override
    public int save(PrincipleApproval principleApproval) {
        int result = super.save(principleApproval);

        WorkflowInstance instance = new WorkflowInstance();
        instance.setWorkflowDefineId(principleApproval.getWorkflowDefineId());
        instance.setFormId(principleApproval.getId());
        instance.setTitle("员工违纪审批单:" + DateUtils.getNowTime());

        workflowHelper.saveAndStartProcess(instance, principleApproval.getNextStepUserId());

        return result;
    }
}